package com.lzh.chatnote.common.config.threadPoolConfig;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ThreadFactory;

@Slf4j
@AllArgsConstructor
public class MyThreadFactory implements ThreadFactory {

    private final ThreadFactory original;


    //自定义工厂实现线程异常处理
    @Override
    public Thread newThread(Runnable r) {

        //执行了spring自己的逻辑
        Thread thread = original.newThread(r);

        //额外的装饰器自己的逻辑
        thread.setUncaughtExceptionHandler(GlobalUncaughtExceptionHandler.getInstance());
        return thread;
    }
}
